/**
 * 工具函数
 */
function cellPhoneNumber(cell) {
	return /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/.test(
		cell
	)
}
function checkPhoneNum(check) {
	return /^[a-zA-Z]\w{5,11}$/.test(check)
}
//弹窗toast封装
function showToast(type, text, callback) {
	const toast = document.createElement('div')
	toast.className = 'toast'
	toast.innerHTML = `<p class="iconfont ${
		type === 0 ? 'icon-duihao' : 'icon-cuowuguanbiquxiao'
	}"></p><p>${text}</p>`

	document.body.appendChild(toast)
	window.setTimeout(function () {
		toast.remove()
		callback()
	}, 3000)
}
//状态框
function showuhdy(type) {
	let uhdy = document.createElement('div')
	uhdy.className = 'showUhdy'
	uhdy.innerHTML = `<a class="${
		type == 0 ? 'showon' : ''
	}" href='./index.html'>
    <span class="iconfont icon-home"></span>
    <p>首页</p></a>
    <a class="${type == 1 ? 'showon' : ''}" href="./CourseTraining.html"0>
    <span class="iconfont icon-xintiaojiankangyundongyiliaobaohuxinshuai"></span>
    <p>运动</p></a>
    <a class="${type == 2 ? 'showon' : ''}" href="./follow.html">
    <span class="iconfont icon-pintu"></span>
	<p>圈子</p></a>
    <a class="${type == 3 ? 'showon' : ''}" href="./my.html">
	<span class="iconfont icon-wode"></span>
	<p>我的</p></a>`
	document.body.appendChild(uhdy)
}
//防止未登录进行其他页面
function namichref() {
	let userID = JSON.parse(localStorage.getItem('users'))
	if (!userID) {
		location.href = './login.html'
	}
}
function addZero(n){
    return n<10?'0'+n:n
}
window.utils = {
	cellPhoneNumber,
	checkPhoneNum,
	showToast,
	showuhdy,
	namichref,
	addZero,
}
